import Vue from "vue";
import Axios from "axios";

let domain =
  "https://www.fastmock.site/mock/1d57e018d79a2ce3b74667e170734a3f/api";

const isProduction = process.env.NODE_ENV === "production";
const api = Axios.create();
api.defaults.baseURL = isProduction ? "" : domain;
api.defaults.timeout = isProduction ? 10000 : 3000;
api.defaults.headers.post["Content-Type"] = "application/json";
api.defaults.headers.post["token"] = localStorage.getItem("token") || "";
api.interceptors.request.use(
  function (config) {
    //console.log(config);
    return config;
  },
  function (error) {
    // 对请求错误
    return Promise.reject(error);
  }
);
api.interceptors.response.use(
  function (response) {
    return response;
  },
  function (error) {
    return Promise.reject(error);
  }
);

Vue.prototype.$api = api;

export default api;
